/*
 * @Author: hongbin
 * @Date: 2022-10-21 18:30:52
 * @LastEditors: hongbin
 * @LastEditTime: 2022-10-21 18:30:52
 * @Description: 构造立体几何
 */
import OctreeCSG from "./OctreeCSG/OctreeCSG";

type csgOperationsType = "union" | "subtract" | "intersect";

/**
 * @description: 构造立体几何
 * @param {THREE.Mesh} mesh1
 * @param {THREE.Mesh} mesh2
 * @param {csgOperationsType} operation "union" | "subtract" | "intersect"
 * @return {THREE.BufferGeometry}
 */
export function ConstructiveSolidGeometry(
    mesh1: THREE.Mesh,
    mesh2: THREE.Mesh,
    operation: csgOperationsType
) {
    const mesh1Octree = OctreeCSG.fromMesh(mesh1);
    const mesh2Octree = OctreeCSG.fromMesh(mesh2);
    const resultOctree = OctreeCSG[operation](mesh1Octree, mesh2Octree, false);
    const resultGeom = OctreeCSG.toGeometry(resultOctree);
    return resultGeom;
}
